package com.example.springboot.common.utils.ThrowUtil;


import com.example.springboot.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;

/**
 * 抛异常工具类
 */
@Slf4j
public class ThrowUtil {
    /**
     * 条件成立则抛异常
     *
     * @param condition
     */
    public static void throwIf(boolean condition, String msg) {
        if (condition) {
            log.error(msg);
            throw new ServiceException(msg);
        }
    }

    public static void throwIf(boolean condition, String msg, String code) {
        if (condition) {
            throw new ServiceException(msg, code);
        }
    }

    public static void throwIf(String msg) {
        throw new ServiceException(msg);
    }

    public static void throwIf(String msg, String code) {
        throw new ServiceException(msg, code);
    }
}
